<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>视频列表</title>
    <%@ include file="inc/css.jsp" %>
</head>

<body>
<div id="videos" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">视频列表</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <input type="hidden" id="companyUserId" value="${companyUserId}"/>
                        <a href="company/video/show" class="btn btn-outline btn-info btn-lg" role="button">添加视频</a>

                        <form class="navbar-form navbar-right" role="search">
                            <div class="form-group">
                                <input type="text" class="form-control" id="name" maxlength="20" placeholder="视频名称"/>
                            </div>
                            <div class="form-group">
                                <label>行业分类：</label>
                                <select id="videoTypeList" style="width: 120px;" class="form-control"></select>
                            </div>
                            <div class="form-group">
                                <label>视频状态：</label>
                                <select id="statusList" style="width: 120px;" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">待审核</option>
                                    <option value="2">审核失败</option>
                                    <option value="3">投放中</option>
                                    <option value="4">已下架</option>
                                </select>
                            </div>
                            <button type="button" id="c_search" class="btn btn-primary btn-sm">搜索</button>
                        </form>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">

                        <div class="table-responsive">

                            <table class="table table-striped table-bordered table-hover" id="dataTables">
                                <colgroup>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>视频名称</th>
                                    <th>发布时间</th>
                                    <th>行业</th>
                                    <th>视频类型</th>
                                    <th>投放次数</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->

<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">
                确定删除选中的视频？删除后数据将无法恢复
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="_companyVideoList.fn.confirmDel()" class="btn btn-primary">确定</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<div class="modal fade" id="checkModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body" id="showDivBody">
                确定将该视频审核为成功？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="_companyVideoList.fn.changeStatus()" class="btn btn-primary">确定</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<%@ include file="inc/footer.jsp" %>
</body>

<script type="text/javascript">
    var _companyVideoList = {
        v: {
            id: "_companyVideoList",
            list: [],
            dTable: null,
            videoId: 0,
            status: 0
        },
        fn: {
            init: function () {
                _companyVideoList.fn.getSelectList();

                _companyVideoList.fn.dataTableInit();

                // 查询
                $("#c_search").click(function () {
                    _companyVideoList.v.dTable.ajax.reload();
                });
            },
            dataTableInit: function () {
                _companyVideoList.v.dTable = $leoman.dataTable($('#dataTables'), {
                    "processing": true,
                    "serverSide": true,
                    "searching": false,
                    "ordering": false,
                    "ajax": {
                        "url": "company/video/list",
                        "type": "POST"
                    },
                    "columns": [
                        {
                            "data": "name",
                            render: function (data) {
                                if (null == data || data == '') {
                                    return '';
                                } else {
                                    if (data.length > 10) {
                                        return data.substring(0, 10) + '...';
                                    } else {
                                        return data;
                                    }
                                }
                            }
                        },
                        {
                            "data": "createTime",
                            render: function (data) {
                                return formatJsonDateTime(data, 'yyyy-MM-dd hh:mm:ss');
                            }
                        },
                        {"data": "videoType.name"},
                        {
                            "data": "sendType",
                            render: function (data) {
                                var showName = "";
                                switch (Number(data)) {
                                    case 1:
                                        showName = "一般形式";
                                        break;
                                    case 2:
                                        showName = "红包形式";
                                        break;
                                    case 3:
                                        showName = "其他形式";
                                        break;
                                    case 4:
                                        showName = "免费形式";
                                        break;
                                }
                                return showName;
                            }
                        },
                        {"data": "recordNum"},
                        {
                            "data": null,
                            render: function (data) {
                                var showName = "";
                                switch (Number(data.tempStatus)) {
                                    case 0:
                                        showName = "待审核";
                                        break;
                                    case 1:
                                        showName = "审核成功";
                                        break;
                                    case 2:
                                        showName = "审核失败";
                                        break;
                                    case 3:
                                        showName = "投放中";
                                        break;
                                    case 4:
                                        showName = "已下架";
                                        break;
                                    case 5:
                                        showName = "未投放";
                                        break;
                                }
                                return showName + data.tempContent;
                            }
                        },
                        {"data": ""}
                    ],
                    "columnDefs": [
                        {
                            "data": null,
                            "defaultContent": "<a title='查看详情' class='btn btn-primary btn-circle edit'>" +
                            "<i class='fa fa-eye'></i>" +
                            "</a>" +
                            "<a style='display: none;margin-left: 8px;' title='再次投放' class='btn btn-success btn-circle addRecord'>" +
                            "<i class='fa fa-send'></i>" +
                            "</a>" +
                            "<a style='display: none;margin-left: 8px;' title='删除' class='btn btn-danger btn-circle delete'>" +
                            "<i class='fa fa-trash'></i>" +
                            "</a>" +
                            "&nbsp;&nbsp;" +
                            "<button type='button' style='display: none' title='下架' class='btn btn-warning btn-circle noShopping'>" +
                            "<i class='fa fa-arrow-down'></i>" +
                            "</button>",
                            "targets": -1
                        }
                    ],
                    "createdRow": function (row, data, index) {
                        _companyVideoList.v.list.push(data);
                    },
                    rowCallback: function (row, data) {
                        //渲染样式
                        switch (Number(data.tempStatus)) {
                            case 3:
                                // 投放中
                                if (null != data.tempContent && data.tempContent != '' && data.tempContent.length > 9) {
                                    $('td', row).last().find(".noShopping").css("display", "");
                                }
                                break;
                            case 2:
                                // 审核失败
                                $('td', row).last().find(".delete").css("display", "");
                                break;
                            case 4:
                            // 已下架
                            case 5:
                                // 未投放
                                $('td', row).last().find(".addRecord").css("display", "");
                                $('td', row).last().find(".delete").css("display", "");
                                break;
                        }

                        $('td', row).last().find(".edit").attr("href", 'company/video/show?videoId=' + data.id);

                        $('td', row).last().find(".addRecord").attr("href", 'company/video/record?videoId=' + data.id);

                        $('td', row).last().find(".delete").click(function () {
                            _companyVideoList.v.videoId = data.id;
                            $('#delModal').modal("show");
                        });

                        $('td', row).last().find(".noShopping").click(function () {
                            _companyVideoList.v.videoId = data.id;
                            _companyVideoList.v.status = 0;
                            $('#showDivBody').html('确定将该视频下架？');
                            $('#checkModal').modal("show");
                        });
                    },
                    "fnServerParams": function (aoData) {
                        aoData.companyUserId = $('#companyUserId').val();
                        aoData.name = $('#name').val();
                        aoData.videoTypeId = $('#videoTypeList option:selected').val();
                        aoData.status = $('#statusList option:selected').val();
                    },
                    "fnDrawCallback": function (row) {
                        $leoman.uiform();
                    }
                });
            },
            changeStatus: function () {
                $leoman.ajax("company/video/changeShopping", {
                    "videoId": _companyVideoList.v.videoId,
                    "status": _companyVideoList.v.status
                }, function (result) {
                    if (result == 1) {
                        $leoman.notify("操作成功", "success");
                        $('#checkModal').modal("hide");
                        _companyVideoList.v.dTable.ajax.reload(null, false);
                    } else {
                        $leoman.notify("操作失败", "error");
                    }
                });
            },
            confirmDel: function () {
                $leoman.ajax("company/video/delete", {
                    "videoId": _companyVideoList.v.videoId
                }, function (result) {
                    if (result == 1) {
                        $leoman.notify("操作成功", "success");
                        $('#delModal').modal("hide");
                        _companyVideoList.v.dTable.ajax.reload(null, false);
                    } else {
                        $leoman.notify("操作失败", "error");
                    }
                });
            },
            getSelectList: function () {
                $leoman.ajax("common/videoTypeList", null, function (result) {
                    if (null != result) {
                        var content = "<option value=''>请选择分类</option>";
                        jQuery.each(result, function (i, item) {
                            content += "<option value='" + item.id + "'>" + item.name + "</option>";
                        });
                        $('#videoTypeList').append(content);
                    } else {
                        $leoman.notify("获取分类信息失败", "error");
                    }
                });
            }
        }
    }

    $(document).ready(function () {
        _companyVideoList.fn.init();
    });

</script>

</html>